package com.zzl.study.sharding.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzl.study.sharding.domain.People;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: zhangzl
 * @date: 2022/7/21 9:30
 * @version: 1.0
 * @description: 人员Mapper
 */
@Repository
public interface PeopleMapper extends BaseMapper<People> {

    /**
     * 查询人员集合，关联字典表
     *
     * @return 人员集合
     */
    @Select("select p.id, p.name, p.sex, d.dict_name as sex_description, p.age from t_people p inner join t_dict d on p.sex = d.id")
    List<People> selectPeopleList();

    /**
     * 根据ID查询人员，关联字典表
     *
     * @param id 人员ID
     * @return 人员对象
     */
    @Select("select p.id, p.name, p.sex, d.dict_name as sex_description, p.age from t_people p inner join t_dict d on p.sex = d.id where p.id = #{id}")
    People selectPeopleById(@Param("id") Long id);

}
